import Axios from 'axios'
import Qs from 'qs'
import { apiUrl, apiUrlDev } from './config'

Axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'

const DEFAULT_URL = process.env.NODE_ENV === 'development' ? apiUrlDev : apiUrl

export default {
  get(_url, _data) {
    const url = DEFAULT_URL + _url
    const data = Qs.stringify(Object.assign({}, _data))

    return Axios.get(url, data)
  },
  post(_url, _data) {
    const url = DEFAULT_URL + _url
    const data = Qs.stringify(Object.assign({}, _data))

    return Axios.post(url, data)
  }
}
